package com.oocl.o2o.merchant.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.oocl.o2o.merchant.dao.FoodDao;
import com.oocl.o2o.merchant.dao.FoodTypeDao;
import com.oocl.o2o.merchant.dao.MerchantDao;
import com.oocl.o2o.merchant.entity.Food;
import com.oocl.o2o.merchant.entity.FoodType;
import com.oocl.o2o.merchant.entity.Merchant;
import com.oocl.o2o.merchant.service.FoodManager;

@Service
public class FoodManagerImpl implements FoodManager {
	@Autowired
	private FoodDao foodDao;
	@Autowired
	private MerchantDao merchantDao;
	@Autowired
	private FoodTypeDao foodTypeDao;

	@Override
	@Transactional
	public Food add(Food food) {
		// may be will return null, may be need to handle it
		return foodDao.add(food);
	}

	@Override
	@Transactional
	public Food delete(String id) {
		return foodDao.delete(id);
	}

	@Override
	@Transactional
	public Food update(Food food) {
		return foodDao.update(food);
	}

	@Override
	@Transactional
	public Food findById(String id) {
		return foodDao.findById(id);
	}

	@Override
	@Transactional
	public List<Food> findByMerchantId(String merchantId) {
		Merchant merchant = merchantDao.findById(merchantId);
		if (merchant == null)
			return null;
		List<Food> foods = merchant.getFoods();
		foods.size();
		return foods;
	}

	@Override
	public List<FoodType> findFoodType() {
		return foodTypeDao.findAll();
	}
}
